
<cfset sXML = xmlnew() />
<cfset sXML.xmlroot = XMLElemNew(sXML,"datamaps") />
<cfset sXML.datamaps.datamap = XMLElemNew(sXML,"datamap") />
<cfset sXML.datamaps.datamap.source = XMLElemNew(sXML,"source") />
<cfset sXML.datamaps.datamap.source[1].datasource = XMLElemNew(sXML,"datasource") />
<cfset sXML.datamaps.datamap.source[1].datasource.xmltext = Trim(source) />
<cfset sXML.datamaps.datamap.source[1].tablename = XMLElemNew(sXML,"tablename") />
<cfset sXML.datamaps.datamap.source[1].tablename.xmltext = Trim(sourcetable) />
<cfset sXML.datamaps.datamap.source[1].username = XMLElemNew(sXML,"username") />
<cfset sXML.datamaps.datamap.source[1].username.xmltext = Trim(sourceusername) />
<cfset sXML.datamaps.datamap.source[1].password = XMLElemNew(sXML,"password") />
<cfset sXML.datamaps.datamap.source[1].password.xmltext = Trim(sourcepassword) />
<cfset sXML.datamaps.datamap.source[1].condition = XMLElemNew(sXML,"condition") />
<cfsavecontent variable="scondition">
	<cfoutput>#trim(preservesinglequotes(form.sourcecondition))#</cfoutput>
</cfsavecontent>
<cfset sXML.datamaps.datamap.source[1].condition.XmlCData = Trim(scondition) />

<cfif trim(form.sourcecustomcode) NEQ "">
	<cfset sXML.datamaps.datamap.source[1].customcode = XMLElemNew(sXML,"customcode") />
	<cfsavecontent variable="scustomcode">
			<cfoutput>#preservesinglequotes(form.sourcecustomcode)#</cfoutput>
	</cfsavecontent>
	<cfset sXML.datamaps.datamap.source[1].customcode.XmlCData = Trim(scustomcode) />
</cfif>

<cfset sXML.datamaps.datamap.target = XMLElemNew(sXML,"target") />
<cfset sXML.datamaps.datamap.target[1].datasource = XMLElemNew(sXML,"datasource") />
<cfset sXML.datamaps.datamap.target[1].datasource.xmltext = Trim(target) />
<cfset sXML.datamaps.datamap.target[1].tablename = XMLElemNew(sXML,"tablename") />
<cfset sXML.datamaps.datamap.target[1].tablename.xmltext = Trim(targettable) />
<cfset sXML.datamaps.datamap.target[1].username = XMLElemNew(sXML,"username") />
<cfset sXML.datamaps.datamap.target[1].username.xmltext = Trim(targetusername) />
<cfset sXML.datamaps.datamap.target[1].password = XMLElemNew(sXML,"password") />
<cfset sXML.datamaps.datamap.target[1].password.xmltext = Trim(targetpassword) />
<cfset sXML.datamaps.datamap.target[1].condition = XMLElemNew(sXML,"condition") />

<cfsavecontent variable="scondition">
	<cfoutput>#trim(preservesinglequotes(form.targetcondition))#</cfoutput>
</cfsavecontent>
<cfset sXML.datamaps.datamap.target[1].condition.XmlCData = Trim(scondition) />

<cfif Trim(form.targetcustomcode) NEQ "">
	<cfset sXML.datamaps.datamap.target[1].customcode = XMLElemNew(sXML,"customcode") />
	<cfsavecontent variable="scustomcode">
			<cfoutput>#preservesinglequotes(form.targetcustomcode)#</cfoutput>
	</cfsavecontent>
	<cfset sXML.datamaps.datamap.target[1].customcode.XmlCData = Trim(scustomcode) />
</cfif>

<cfset sXML.datamaps.datamap.columnmap = XMLElemNew(sXML,"columnmap") />
<cfset cnt = 1 />
<cfset thecolumns = sXML.datamaps.datamap.columnmap>
<cfloop collection="#form#" item="formEL">
	<cfif formEL NEQ 'FIELDNAMES' AND Left(formEL,12) EQ 'targetcolumn'>
		<cfset columnNum = "" />
		<cfset column = "" />
		<cfif LEN(formEL) GT 12>
			<cfset columnNum = Right(formEL,len(formEL)-12) />
		</cfif>
		<cfif ListLen(evaluate('form.sourceColumn' & columnNum),',') EQ 3>
			<cfset thecolumns.xmlchildren[cnt] = XMLElemNew(sXML,"column") />
			<cfset thecolumns.xmlchildren[cnt].XmlAttributes = XMLElemNew(sXML,"XmlAttributes") />
			<cfset thecolumns.xmlchildren[cnt].XmlAttributes.source = XMLElemNew(sXML ,"source") />
			<cfset thecolumns.xmlchildren[cnt].XmlAttributes.source = Trim(ListGetAt(evaluate('form.sourceColumn' & columnNum),2)) />
		
			<cfif Trim(Evaluate('form.cfVariableColumn' & columnNum)) NEQ "">
				<cfset thecolumns.xmlchildren[cnt].XmlAttributes.cfVariable = XMLElemNew(sXML,"cfVariable") />
				<cfset thecolumns.xmlchildren[cnt].XmlAttributes.cfVariable = Trim(Evaluate('form.cfVariableColumn' & columnNum)) />
			</cfif>
			
			<cfset thecolumns.xmlchildren[cnt].XmlAttributes.target = XMLElemNew(sXML,"cfVariable") />
			<cfset thecolumns.xmlchildren[cnt].XmlAttributes.target = Trim(ListGetAt(evaluate('form.targetColumn' & columnNum),2)) />
			<cfset thecolumns.xmlchildren[cnt].XmlAttributes.targetIsPK = XMLElemNew(sXML,"targetIsPK") />
			<cfset thecolumns.xmlchildren[cnt].XmlAttributes.targetIsPK = Trim(evaluate('form.targetispkcolumn' & columnNum)) />
			<cfset thecolumns.xmlchildren[cnt].XmlAttributes.datatype = XMLElemNew(sXML,"datatype") />
			<cfset thecolumns.xmlchildren[cnt].XmlAttributes.datatype = Trim(evaluate('form.dataTypeColumn' & columnNum)) />
			
			<cfif Trim(evaluate('form.customcode' & columnNum)) NEQ "">
				<cfsavecontent variable="sCustCode"><![CDATA[  <cfoutput>#Trim(evaluate('form.customcode' & columnNum))#</cfoutput>	]]></cfsavecontent>
				
				<cfset thecolumns.xmlchildren[cnt].customcode = XmlElemNew(sXML,"customcode")/>
				<cfset thecolumns.xmlchildren[cnt].customcode.XmlCData = sCustCode />
			</cfif>
			<cfset cnt = cnt + 1/>
		</cfif>
	</cfif>
</cfloop>
<cfdump var="#sxml#">

<cfset t = createobject("component","cfcDataMapper.org.mgraf.cfcdatamapper.datamapper").init()>
<cfset t.configure(sxml,'xml')>
<cfset t.processMap()>

<!--- <cffile action="write" file="#expandpath('ddd.xml')#" output="#lcase(sXML)#" /> --->

<!--- <cfdump var="#XMLParse(dataMapXML)#"> --->